home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
cmd_general3.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
18KB
|
610 lines
#include:util.g
#empire.g
#empfunc.g
/* globals needed by cmd_build: */
*char StartPtr;
uint TotalCost;
bool HadBridge, HadHarbor, CouldBuild;
/* ****************************** */
/*
* doBuild - part of cmd_build
*/
proc doBuild(int r, c; Sector_t s)void:
[100] char buf;
channel output text promptChan;
int rSpan, cSpan;
uint cost;
Sector_t sSpan;
Ship_t sh;
ShipType_t typ;
char dir;
if s.s_type = s_bridgeHead then
HadBridge := true;
if s.s_production = 127 and
ThisCountry*.c_money >= make(World.w_bridgeCost, int) then
CouldBuild := true;
open(promptChan, &buf[0]);
write(promptChan; "Bridge head at ", r, ',', c,
"; build span in what direction? (udlr) ");
close(promptChan);
if reqBridgeDirection(&dir, &buf[0]) then
rSpan := r;
cSpan := c;
case dir
incase 'u':
rSpan := rSpan - 1;
incase 'd':
rSpan := rSpan + 1;
incase 'l':
cSpan := cSpan - 1;
incase 'r':
cSpan := cSpan + 1;
esac;
readSector(rSpan, cSpan, sSpan);
if sSpan.s_type = s_water then
s.s_production := 0;
ThisCountry*.c_money :=
ThisCountry*.c_money - World.w_bridgeCost;
TotalCost := TotalCost + World.w_bridgeCost;
sSpan.s_type := s_bridgeSpan;
sSpan.s_owner := ThisCountryNumber;
sSpan.s_efficiency := 100;
writeQuan(s, it_shells, 0);
sSpan.s_lastUpdate :=
CurrentTime() / (60 * 30) * (60 * 30);
writeSector(rSpan, cSpan, sSpan);
writeln(Chout; "Bridge span built over ",
rSpan, ',', cSpan);
writeSector(r, c, s);
else
err("can only build bridge spans over water");
fi;
fi;
fi;
elif s.s_type = s_harbour then
HadHarbor := true;
open(promptChan, &buf[0]);
write(promptChan; s.s_production,
" production units in harbor at ", r, ',', c,
"; kind of ship? ");
close(promptChan);
if reqShipType(&typ, &buf[0]) then
cost := World.w_shipCost[typ];
if cost > s.s_production then
err("insufficient production units");
elif make(cost * World.w_shipCostMult, int) >
ThisCountry*.c_money then
err("you don't have enough money");
else
s.s_production := s.s_production - cost;
ThisCountry*.c_money :=
ThisCountry*.c_money - cost * World.w_shipCostMult;
TotalCost := TotalCost + cost * World.w_shipCostMult;
sh.sh_lastUpdate :=
CurrentTime() / (30 * 60) * (30 * 60);
sh.sh_price := 0;
sh.sh_type := typ;
sh.sh_fleet := '*';
sh.sh_owner := ThisCountryNumber;
sh.sh_efficiency := 50;
sh.sh_row := transRow(r);
sh.sh_col := transCol(c);
sh.sh_crew := 0;
sh.sh_shells := 0;
sh.sh_guns := 0;
sh.sh_planes := 0;
sh.sh_ore := 0;
sh.sh_bars := 0;
sh.sh_mobility := 0;
writeShip(World.w_shipNext, sh);
s.s_shipCount := s.s_shipCount + 1;
writeSector(r, c, s);
writeln(Chout; "Built ", getShipName(typ),
" number ", World.w_shipNext, " at ", r, ',', c);
World.w_shipNext := World.w_shipNext + 1;
fi;
fi;
fi;
InputPtr := StartPtr;
corp;
proc cmd_build()bool:
if reqSectors("Sectors to build in? ") then
skipBlanks();
StartPtr := InputPtr;
HadBridge := false;
HadHarbor := false;
CouldBuild := false;
TotalCost := 0;
pretend(scanSectors(doBuild), void);
if not HadBridge and not HadHarbor then
err("can only build at bridge spans or harbors");
elif HadBridge and not CouldBuild then
err("insufficient money/production");
elif TotalCost ~= 0 then
writeln(Chout; "That just cost you $", TotalCost, '!');
fi;
true
else
false
fi
corp;
proc cmd_declare()bool:
uint country, what;
if reqChoice(&what, "neutrality\ealliance\ewar\e",
"Enter relationship: ") and
doSkipBlanks() and
reqCountry(&country, "Declare with which country? ") then
if country = ThisCountryNumber then
err("your relation to yourself is none of Empire's concern");
false
else
if ThisCountry*.c_relations[country] = r_war then
news(n_disavow_war, ThisCountryNumber, country);
elif ThisCountry*.c_relations[country] = r_allied then
news(n_disavow_ally, ThisCountryNumber, country);
fi;
ThisCountry*.c_relations[country] := r_neutral + what;
news(
case r_neutral + what
incase r_neutral:
n_decl_neut
incase r_war:
n_decl_war
incase r_allied:
n_decl_ally
esac, ThisCountryNumber, country);
true
fi
else
false
fi
corp;
proc cmd_lend()bool:
Loan_t loan;
uint loanNumber, loanee, amount, rate, duration;
if ThisCountry*.c_money > 32767 then
loanNumber := 32767;
else
loanNumber := ThisCountry*.c_money;
fi;
if loanNumber = 0 then
err("you have no money to lend");
true
elif reqCountry(&loanee, "Country to loan to? ") and
doSkipBlanks() and
reqPosRange(&amount, loanNumber, "Amount to loan? ") and
doSkipBlanks() and
reqPosRange(&rate, 127, "Interest rate (max 127%)? ") and
doSkipBlanks() and
reqPosRange(&duration, 127, "Duration in days (max 127)? ") then
if loanee = ThisCountryNumber then
err("can't lend yourself money");
false
elif amount = 0 or duration = 0 then
err("loan cancelled");
false
else
loan.l_lastPay := CurrentTime() / (60 * 30) * (60 * 30);
loan.l_dueDate :=
loan.l_lastPay + (60 * 60 * 24) * make(duration, ulong);
loan.l_amount := amount;
loan.l_paid := 0;
loan.l_duration := duration;
loan.l_rate := rate;
loan.l_loaner := ThisCountryNumber;
loan.l_loanee := loanee;
loan.l_state := l_offered;
writeLoan(World.w_loanNext, loan);
telegramStart(DEITY, loanee);
writeln(TelegramChannel; &ThisCountry*.c_name[0],
" has offered you loan \#", World.w_loanNext, '.');
telegramEnd();
writeln(Chout; "You have offered loan \#", World.w_loanNext, '.');
World.w_loanNext := World.w_loanNext + 1;
true
fi
else
false
fi
corp;
proc cmd_accept()bool:
Loan_t loan;
uint loanNumber, choice;
if World.w_loanNext = 0 then
err("there are no loans yet");
false
elif reqPosRange(&loanNumber, World.w_loanNext - 1,
"Loan to accept? ") then
readLoan(loanNumber, loan);
if loan.l_loanee ~= ThisCountryNumber then
err("that loan is not offered to you");
false
elif loan.l_state ~= l_offered then
err("that loan is not an outstanding offer");
false
else
write(Chout; "Loan \#", loanNumber, " offered by ",
&Country[loan.l_loaner].c_name[0], " on ");
writeDate(loan.l_lastPay);
writeln(Chout;);
writeln(Chout; "Principal $", loan.l_amount, " at ", loan.l_rate,
"% interest lasting ", loan.l_duration, " days");
write(Chout; "This offer will be retracted if not accepted by ");
writeDate(loan.l_dueDate);
writeln(Chout;);
if make(loan.l_amount, long) > Country[loan.l_loaner].c_money then
writeln(Chout; &Country[loan.l_loaner].c_name[0],
" no longer has the funds...");
loan.l_amount := Country[loan.l_loaner].c_money;
writeln(Chout; "You may borrow $", loan.l_amount,
" on the same terms.");
fi;
InputPtr* := '\e';
while not reqChoice(&choice, "accept\edecline\epostpone\e",
"Accept/decline/postpone this loan? ") do
od;
telegramStart(DEITY, loan.l_loaner);
case choice
incase 0:
ThisCountry*.c_money := ThisCountry*.c_money + loan.l_amount;
Country[loan.l_loaner].c_money :=
Country[loan.l_loaner].c_money - loan.l_amount;
loan.l_paid := 0;
loan.l_lastPay := CurrentTime() / (60 * 30) * (60 * 30);
loan.l_dueDate := loan.l_lastPay +
(60 * 60 * 24) * make(loan.l_duration, ulong);
loan.l_state := l_outstanding;
writeLoan(loanNumber, loan);
writeln(TelegramChannel; "Loan \#", loanNumber,
" accepted by ", &ThisCountry*.c_name[0]);
news(n_make_loan, loan.l_loaner, ThisCountryNumber);
writeln(Chout; "You are now $", loan.l_amount,
" richer (sort of)");
incase 1:
loan.l_state := l_declined;
writeLoan(loanNumber, loan);
writeln(TelegramChannel; "Loan \#", loanNumber,
" declined by ", &ThisCountry*.c_name[0]);
writeln(Chout; "You declined loan \#", loanNumber);
incase 2:
writeln(TelegramChannel; "Loan \#", loanNumber,
" considered by ", &ThisCountry*.c_name[0]);
writeln(Chout; "Okay...");
esac;
telegramEnd();
true
fi
else
false
fi
corp;
proc cmd_repay()bool:
Loan_t loan;
uint loanNumber, amount;
ulong now, due, lastPay, rate, regularTime, extraTime, owed;
if World.w_loanNext = 0 then
err("there are no loans yet");
false
elif reqPosRange(&loanNumber, World.w_loanNext - 1,
"Repay which loan? ") then
readLoan(loanNumber, loan);
if loan.l_state ~= l_outstanding or
loan.l_loanee ~= ThisCountryNumber then
err("you don't owe any money on that loan");
false
else
now := CurrentTime() / (60 * 30);
due := loan.l_dueDate / (60 * 30);
lastPay := loan.l_lastPay / (60 * 30);
rate := make(loan.l_rate, ulong) * 1000;
rate := rate / (make(loan.l_duration, ulong) * (24 * 2));
if now <= due then
regularTime := now - lastPay;
extraTime := 0;
else
if lastPay <= due then
regularTime := due - lastPay;
extraTime := now - due;
else
regularTime := 0;
extraTime := now - lastPay;
fi;
fi;
owed := ((regularTime + extraTime * 2) * rate / 100 + 1000) *
loan.l_amount / 1000;
if owed > 65535 then
owed := 65535;
fi;
writeln(Chout; "You owe $", owed, " on that loan.");
skipBlanks();
if reqPosRange(&amount, owed, "Pay how much? ") then
if make(amount, long) > ThisCountry*.c_money then
err("you don't have that much money");
else
ThisCountry*.c_money := ThisCountry*.c_money - amount;
Country[loan.l_loaner].c_money :=
Country[loan.l_loaner].c_money + amount;
loan.l_lastPay := now * (60 * 30);
telegramStart(DEITY, loan.l_loaner);
if amount = owed then
writeln(TelegramChannel; &ThisCountry*.c_name[0],
" paid off loan \#", loanNumber, " with $",
amount);
loan.l_state := l_paidUp;
news(n_repay_loan, ThisCountryNumber, loan.l_loaner);
writeln(Chout; "Congratulations, you've paid off "
"the loan!");
else
writeln(TelegramChannel; &ThisCountry*.c_name[0],
" paid $", amount, " on loan \#", loanNumber);
owed := owed - amount;
if owed > 65535 then
owed := 65535;
fi;
loan.l_amount := owed;
if amount > 65535 - loan.l_paid then
amount := 65535 - loan.l_paid;
fi;
loan.l_paid := loan.l_paid + amount;
fi;
telegramEnd();
writeLoan(loanNumber, loan);
fi;
true
else
false
fi
fi
else
false
fi
corp;
/*
* dumpLoan - part of cmd_ledger. Return 'true' if loan involves this user.
*/
proc dumpLoan(uint loanNumber)bool:
Loan_t loan;
ulong now, due, lastPay, rate, regularTime, extraTime, owed;
readLoan(loanNumber, loan);
if (loan.l_loaner = ThisCountryNumber or
loan.l_loanee = ThisCountryNumber) and
loan.l_state ~= l_declined and loan.l_state ~= l_paidUp then
writeln(Chout;);
writeln(Chout; "Loan \#", loanNumber, " from ",
&Country[loan.l_loaner].c_name[0], " to ",
&Country[loan.l_loanee].c_name[0]);
if loan.l_state = l_offered then
writeln(Chout; "(proposed) principal = $", loan.l_amount,
" interest rate = ", loan.l_rate,
"% duration (days) = ", loan.l_duration);
if loan.l_dueDate < CurrentTime() / (30 * 60) * (30 * 60) then
writeln(Chout; "This offer has expired");
loan.l_state := l_paidUp;
writeLoan(loanNumber, loan);
else
write(Chout; "Loan must be accepted by ");
writeDate(loan.l_dueDate);
writeln(Chout;);
fi;
else
now := CurrentTime() / (60 * 30);
due := loan.l_dueDate / (60 * 30);
lastPay := loan.l_lastPay / (60 * 30);
rate := make(loan.l_rate, ulong) * 1000;
rate := rate / (make(loan.l_duration, ulong) * (24 * 2));
if now <= due then
regularTime := now - lastPay;
extraTime := 0;
else
if lastPay <= due then
regularTime := due - lastPay;
extraTime := now - due;
else
regularTime := 0;
extraTime := now - lastPay;
fi;
fi;
owed := ((regularTime + extraTime * 2) * rate / 100 + 1000) *
loan.l_amount / 1000;
writeln(Chout; "Amount paid to date: $", loan.l_paid);
writeln(Chout; "Amount due if paid now: $", owed);
if extraTime = 0 then
writeln(Chout; "(if paid on due date): $",
((due - lastPay) * rate / 100 + 1000) *
loan.l_amount / 1000);
write(Chout; "Due date is: ");
writeDate(loan.l_dueDate);
writeln(Chout;);
else
writeln(Chout; " ** In Arrears **");
fi;
fi;
true
else
false
fi
corp;
proc cmd_ledger()void:
uint loanNumber;
bool gotOne;
if World.w_loanNext = 0 then
err("there are no loans yet");
elif InputPtr* = '\e' then
writeln(Chout; " ... ", &ThisCountry*.c_name[0], " Ledger ...");
gotOne := false;
for loanNumber from 0 upto World.w_loanNext - 1 do
if dumpLoan(loanNumber) then
gotOne := true;
fi;
od;
if not gotOne then
writeln(Chout; "The slate is clean (i.e. no entries in ledger)");
fi;
elif getPosRange(&loanNumber, World.w_loanNext - 1) then
if not dumpLoan(loanNumber) then
writeln(Chout; "There is no entry in the ledger for loan \#",
loanNumber);
fi;
fi;
corp;
proc cmd_collect()bool:
Loan_t loan;
Sector_t s;
uint loanNumber, loanee;
int r, c;
ulong now, due, lastPay, rate, regularTime, extraTime, owed, val;
ItemType_t it;
if World.w_loanNext = 0 then
err("there are no loans yet");
false
elif reqPosRange(&loanNumber, World.w_loanNext - 1,
"Loan to collect on? ") then
readLoan(loanNumber, loan);
if loan.l_state ~= l_outstanding or
loan.l_loaner ~= ThisCountryNumber then
writeln(Chout; "You are not owed anything on that loan");
false
elif loan.l_dueDate >= CurrentTime() / (60 * 30) * (60 * 30) then
writeln(Chout; "There has been no default on loan \#", loanNumber);
false
else
loanee := loan.l_loanee;
now := CurrentTime() / (60 * 30);
due := loan.l_dueDate / (60 * 30);
lastPay := loan.l_lastPay / (60 * 30);
rate := make(loan.l_rate, ulong) * 1000;
rate := rate / (make(loan.l_duration, ulong) * (24 * 2));
if now <= due then
regularTime := now - lastPay;
extraTime := 0;
else
if lastPay <= due then
regularTime := due - lastPay;
extraTime := now - due;
else
regularTime := 0;
extraTime := now - lastPay;
fi;
fi;
owed := ((regularTime + extraTime * 2) * rate / 100 + 1000) *
loan.l_amount / 1000;
writeln(Chout; "You are owed $", owed, " on that loan");
skipBlanks();
if reqSector(&r, &c, "Confiscate which sector? ") then
if near(r, c, loanee, nil) then
readSector(r, c, s);
if s.s_owner ~= loanee then
writeln(Chout; &Country[loanee].c_name[0],
" doesn't own sector ", r, ',', c);
else
pretend(updateSector(r, c, s), void);
val := (make(s.s_efficiency, uint) + 100) *
case s.s_type
incase s_sanctuary:
incase s_capital:
127
incase s_ironMine:
incase s_goldMine:
incase s_harbour:
incase s_fortress:
incase s_radar:
20
incase s_bridgeHead:
incase s_bridgeSpan:
15
incase s_wilderness:
5
default:
10
esac;
val := val + s.s_iron * 10;
val := val + s.s_gold * 10;
val := val + s.s_production * 10;
val := val + s.s_mobility * 10;
for it from it_first upto it_last do
val := val + readQuan(s,it) * 10 * getItemCost(it);
od;
val := val * World.w_collectScale / 100;
writeln(Chout;
"That sector (and its contents) is valued at $",
val);
if val <= owed then
s.s_owner := ThisCountryNumber;
s.s_defender := NO_DEFEND;
s.s_checkPoint := 0;
Country[loanee].c_sectorCount :=
Country[loanee].c_sectorCount - 1;
ThisCountry*.c_sectorCount :=
ThisCountry*.c_sectorCount + 1;
if Country[loanee].c_sectorCount = 0 then
Country[loanee].c_status := cs_dead;
writeln(Chout; "You have just confiscated "
"that country's last sector!!");
fi;
news(n_sieze_sector, ThisCountryNumber, loanee);
telegramStart(DEITY, loanee);
write(TelegramChannel; &ThisCountry*.c_name[0],
" siezed ",
unTransRow(loanee, transRow(r)), ',',
unTransCol(loanee, transCol(c)));
if val * 105 / 100 >= owed or
val + 100 >= owed then
news(n_repay_loan, ThisCountryNumber, loanee);
writeln(TelegramChannel;
" to satisfy loan \#", loanNumber);
loan.l_state := l_paidUp;
writeln(Chout; "That loan is now considered "
"repaid");
else
owed := owed - val;
loan.l_amount :=
if owed > 65535 then 65535 else owed fi;
val := val + loan.l_paid;
loan.l_paid :=
if val > 65535 then 65535 else val fi;
loan.l_lastPay := now * (60 * 30);
writeln(TelegramChannel;
"in partial payment of loan \#",
loanNumber);
writeln(Chout; "You are still owed $", owed,
" on loan \#", loanNumber);
fi;
telegramEnd();
writeLoan(loanNumber, loan);
fi;
writeSector(r, c, s);
fi;
else
writeln(Chout; "You are not adjacent to ", r, ',', c);
fi;
fi;
true
fi
else
false
fi
corp;